import type { ConsultType } from "@/enums";
import type {
  ConsultOrderItem,
  orderListRes,
  payUrl,
  orderIdResT,
  getOrderIdT,
  TopDep,
  Image,
  ConsultOrderPreData,
  patientInfoData,
  FollowType,
} from "@/types/consult";
import type {
  AddressItem,
  Logistics,
  OrderDetail,
  OrderPre,
} from "@/types/order";
import { request } from "@/utils/request";
export const getAllDep = () => request<TopDep[]>("/dep/all");

export const uploadImage = (file: File) => {
  const fd = new FormData();
  fd.append("file", file);
  return request<Image>("/upload", "POST", fd);
};
// 就诊信息和抵扣信息  /patient/consult/order/pre
export const OrderPreApi = (type: number, illnessType: number | undefined) =>
  request<ConsultOrderPreData>("/patient/consult/order/pre", "GET", {
    type,
    illnessType,
  });
// 患者详情 /patient/info/{id} get
export const getPatientInfo = (id: string | undefined) =>
  request<patientInfoData>("/patient/info/" + id);
// 生成问诊订单 问诊订单 /patient/consult/order
export const orderIdApi = (params: getOrderIdT) =>
  request<orderIdResT>("/patient/consult/order", "POST", params);
// 支付接口 /patient/consult/pay
export const pay = (
  paymentMethod: number,
  orderId: string,
  payCallback: string
) =>
  request<payUrl>("/patient/consult/pay", "POST", {
    paymentMethod,
    orderId,
    payCallback,
  });
// 问诊记录-订单列表 /patient/consult/order/list
export const getOrderListApi = (
  current?: number,
  pageSize?: number,
  type?: ConsultType
) =>
  request<orderListRes>("/patient/consult/order/list", "GET", {
    type,
    pageSize,
    current,
  });
// 删除订单 /patient/order/{id}
export const deleteOrderApi = (id: string) =>
  request("/patient/order/" + id, "DELETE");

// 取消订单 /patient/order/cancel/{id}
export const canCelOrderApi = (id: string) =>
  request("/patient/order/cancel/" + id, "PUT");
// 查询订单详情信息  /patient/consult/order/detail
export const orderDetailApi = (orderId: string) =>
  request<ConsultOrderItem>("/patient/consult/order/detail", "GET", {
    orderId,
  });
// 查询处方单 /patient/consult/prescription/{id}
export const getPatientConsultPrescription = (id: string) =>
  request<{ url: string; id: string }>(
    "/patient/consult/prescription/" + id,
    "GET"
  );

export const getConsultOrderDetail = (orderId: string) =>
  request<ConsultOrderItem>("/patient/consult/order/detail", "GET", {
    orderId,
  });

export const evaluateConsultOrder = (data: {
  docId: string;
  orderId: string;
  score: number;
  content: string;
  anonymousFlag: 0 | 1;
}) => request("patient/order/evaluate", "POST", data);

export const followOrUnfollow = (id: string, type: FollowType = "doc") =>
  request("like", "POST", { id, type });

export const getPrescriptionPic = (id: string) =>
  request<{ url: string }>(`patient/consult/prescription/${id}`);

// 评价医生 patient/order/evaluate

export const evaluateDoctorApi = (params: {
  docId: string;
  orderId: string;
  score: number;
  content: string;
  anonymousFlag: number;
}) => request("patient/order/evaluate", "POST", params);

// 计算药款  /patient/medicine/order/pre
export const getMedicineOrderPreApi = (prescriptionId: string) =>
  request<OrderPre>("patient/medicine/order/pre", "GET", { prescriptionId });

// 获取地址列表 patient/order/address

export const getAddressListApi = () =>
  request<AddressItem[]>("patient/order/address");

// 查询订单详情信息 /patient/medicine/order/detail/{id}
export const getMedicineOrderDetailApi = (id: string) =>
  request<OrderDetail>("patient/medicine/order/detail/" + id);

// 据处方下药品订单 /patient/medicine/order

export const getMedicineOrderApi = (
  id: string,
  couponId: null,
  addressId: string
) =>
  request<{ id: string }>("patient/medicine/order", "POST", {
    id,
    couponId,
    addressId,
  });

// 查询物流信息 /patient/order/{id}/logistics

export const getLogisticsApi = (id: string) =>
  request<Logistics>("/patient/order/" + id + "/logistics");
